﻿
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        2/16/2009
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteNewsCategoryBUL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using MCWEBSITE.DAL;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.BUL
{
    public class websiteNewsCategoryBUL
    {
        public static int Save(websiteNewsCategoryInfo _websiteNewsCategoryInfo)
        {
            try
            {
                if (_websiteNewsCategoryInfo.CategoryID == 0)
                {
                    return websiteNewsCategoryDAL.Insert(_websiteNewsCategoryInfo);
                }
                else
                {
                    return websiteNewsCategoryDAL.Update(_websiteNewsCategoryInfo);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error on insert theme : {0}", ex.Message));
            }
        }

        public static int Remove(int _CategoryID)
        {
            try
            {
                return websiteNewsCategoryDAL.Delete(_CategoryID);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error on delete Theme : {0}", ex.Message));
            }
        }

        public static List<websiteNewsCategoryInfo> GetParentByLanguageCode(string LanguageCode)
        {
            try
            {
                if (LanguageCode != "" && LanguageCode != null && LanguageCode == "TOÀN BỘ")
                {
                    return websiteNewsCategoryDAL.SelectAllParent();
                }
                else
                {
                    return websiteNewsCategoryDAL.SelectParentByLanguageCode(LanguageCode);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static List<websiteNewsCategoryInfo> GetCategoryByLangAndParent(string LanguageCode, string ParentCategoryID)
        {
            try
            {
                string LanguageCodeParam = "";
                string ParentCategoryIDParam = "";
                if (LanguageCode != "" && LanguageCode != null && LanguageCode != "TOÀN BỘ") LanguageCodeParam = LanguageCode;
                if (ParentCategoryID != "" && ParentCategoryID != null && ParentCategoryID != "TOÀN BỘ") ParentCategoryIDParam = ParentCategoryID;
                return websiteNewsCategoryDAL.SelectCategoryByLangAndParent(LanguageCodeParam, ParentCategoryIDParam);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static List<websiteNewsCategoryInfo> GetAll()
        {
            try
            {
                return websiteNewsCategoryDAL.SelectAll();
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static websiteNewsCategoryInfo Load(int _CategoryID)
        {
            try
            {
                return websiteNewsCategoryDAL.SelectOne(_CategoryID);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }

        public static List<websiteNewsCategoryInfo> Search()
        {
            try
            {
                return websiteNewsCategoryDAL.SelectFilters();
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error:{0}", ex.Message));
            }
        }
    }
}

